﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;


namespace RL
{
    /// <summary>
    /// Логика взаимодействия для wRouteRegistryDialog.xaml
    /// </summary>
    public partial class wRouteRegistryDialog : Window
    {
        private routelistEntities db;

        public routelistEntities DBContext { get { return db; } set { db = value; } }

        public wRouteRegistryDialog()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (null == db) return;
            try
            {
                var ComboSource = from o in db.RouteType orderby o.name select o;
                comboBox1.ItemsSource = ComboSource;
                comboBox1.SelectedItem = (DataContext as Routes).RouteType;
            }
            catch (Exception)
            {
            }
        }

        private void buttonOK_Click(object sender, RoutedEventArgs e)
        {
            if (null == comboBox1.SelectedItem)
            {
                MessageBox.Show("Не выбран тип маршрута");
                return;
            }
            Routes rt = DataContext as Routes;
            if (null == rt) return;
            rt.id_routetype = (comboBox1.SelectedItem as RouteType).id;
            DialogResult = true;
        }

        private void buttonCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}
